<template>
  <div class="base-echart">
    <div ref="echartDivRef" :style="{width:width,height:height}"></div>
  </div>
</template>

<script lang="ts" setup>
import { ref , onMounted , defineProps , withDefaults , watchEffect} from 'vue'
import { EChartsOption } from 'echarts'
import useEchart from '../hooks/useEchart'

//定义props
//定义默认值 withDefaults 方法
const props = withDefaults(
  //传props
  defineProps<{
    width?: string,
    height?: string,
    options: EChartsOption
  }>(),
  {
    width:'100%',
    height:'360px'
  }
)

const echartDivRef = ref<HTMLElement>()

onMounted(() => {
  const { setOptions } = useEchart(echartDivRef.value!)
  //监听数据更新
  watchEffect(() => {
    setOptions(props.options)
  })
})

</script>

<style lang="less" scoped>

</style>
